//                       .::::.
//                     .::::::::.
//                    :::::::::::
//                 ..:::::::::::'
//              '::::::::::::'
//                .::::::::::
//           '::::::::::::::..
//                ..::::::::::::.
//              ``::::::::::::::::
//               ::::``:::::::::'        .:::.
//              ::::'   ':::::'       .::::::::.
//            .::::'      ::::     .:::::::'::::.
//           .:::'       :::::  .:::::::::' ':::::.
//          .::'        :::::.:::::::::'      ':::::.
//         .::'         ::::::::::::::'         ``::::.
//     ...:::           ::::::::::::'              ``::.
//    ```` ':.          ':::::::::'                  ::::..
//                       '.:::::'                    ':'````..
package com.xw.controller.manage;

import com.xw.model.DicGroupLimit;
import com.xw.service.VideosItemService;
import com.xw.service.sysconfig.DicGroupLimitService;
import com.xw.util.PropertiesUtil;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 *
 */
@Controller
@RequestMapping("/manage/videosItem/")
@Scope("prototype")
public class VideosItemController {
    @Resource
    private VideosItemService videosItemService;
    @Resource
    private DicGroupLimitService groupLimitService;

    /**
     * 查询课程的视频
     * @param videoId
     * @return
     */
    @RequestMapping(value = "findVideoItemByVideoId",method = RequestMethod.GET)
    @ResponseBody
    public Map findVideoItemByVideoId(String videoId){
        Map map =videosItemService.findVideoItemByVideoId(videoId);
        return map;
    }
    /**
     * 通过
     * @return
     */
    @RequestMapping(value = "pass",method = RequestMethod.POST)
    @ResponseBody
    public Map pass(String videoItemId,String videoId){
        Map map =videosItemService.pass(videoItemId,videoId);
        return map;
    }
    /**
     * 不通过
     * @return
     */
    @RequestMapping(value = "notPass",method = RequestMethod.POST)
    @ResponseBody
    public Map notPass(String videoItemId,String videoId,String noPassReason){
        Map map =videosItemService.notPass(videoItemId,videoId,noPassReason);
        return map;
    }

    @RequestMapping(value = "toNotPass",method = RequestMethod.GET)
    public String toNotPass(HttpServletRequest request, String videoId, String videoItemId){
        request.setAttribute("videoId", videoId);
        request.setAttribute("videoItemId", videoItemId);
        return "videosItem/noPass";
    }

    @RequestMapping(value = "toPlay",method = RequestMethod.GET)
    public String toPlay(HttpServletRequest request, String videoUrl){
        request.setAttribute("url", PropertiesUtil.getProperty("URL"));
        request.setAttribute("videoUrl", videoUrl);
        return "videosItem/play";
    }




    /**
     * @需求描述:添加视频至课程
     * @创建人:whh
     * @创建时间: 2019/11/23
     * @修改需求:
     * @修改人:
     * @修改时间:
     * @需求思路:
     */
    @RequestMapping(value = "videoItemToVideo",method = RequestMethod.POST)
    @ResponseBody
    public Object videoItemToVideoAction(HttpServletRequest request,String userId, String videoId,String videoItemId){
        Map<String,Object> map = videosItemService.saveVideoItemToVideo(userId,videoId,videoItemId);
        System.out.println(map);
        return map;
    }

    /**
     * 跳转到课程下的视频列表页面
     * @return
     */
    @RequestMapping(value = "findAllByVideoId",method = RequestMethod.GET)
    public String findAllByVideoId(HttpServletRequest request, String glId,String videoId){
        //查询该子导航的增删改查的权限
        DicGroupLimit model = groupLimitService.queryByUUID(glId);
        request.setAttribute("model",model);
        request.setAttribute("url", PropertiesUtil.getProperty("URL"));
        request.setAttribute("videoId", videoId);
        return "videosItem/listByVideoId";
    }
    /**
     * 获取列表数据
     * @return
     */
    @RequestMapping(value = "findAllByVideoIdJson",method = RequestMethod.GET)
    @ResponseBody
    public Object findAllByVideoIdJson(Integer page,Integer limit,String videoId,String videoItemName,Integer videoStatus){
        Map map = videosItemService.findAllByVideoIdJson(page,limit,videoId,videoItemName,videoStatus);
        return map;
    }

    /**
     * 跳转到列表页面
     * @return
     */
    @RequestMapping(value = "findAll",method = RequestMethod.GET)
    public String findAll(HttpServletRequest request, String glId,String videoId){
        //查询该子导航的增删改查的权限
        DicGroupLimit model = groupLimitService.queryByUUID(glId);
        request.setAttribute("model",model);
        request.setAttribute("url", PropertiesUtil.getProperty("URL"));
        request.setAttribute("videoId", videoId);
        return "videosItem/list";
    }

    /**
     * 获取列表数据
     * @return
     */
    @RequestMapping(value = "findAllJson",method = RequestMethod.GET)
    @ResponseBody
    public Object findAllJson(Integer page,Integer limit,String videoId,String videoItemName,Integer videoStatus){
        Map map = videosItemService.findAllJson(page,limit,videoId,videoItemName,videoStatus);
        return map;
    }
}
